package JavaIOTest;

import org.junit.Test;

import java.io.File;
import java.util.Arrays;

/**
 * @author 李泽伟
 */
public class MainTest {
    public static void main(String[] args) {
        //1.构造器1
        File file = new File("D:\\Lizejiang\\importantNetworkCourse\\JavaLearn\\JavaCode\\JavaSELearn\\JavaIO\\hello.txt");
        System.out.println(file);
        //File类的常用方法
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getPath());
        System.out.println(file.length());
        System.out.println(file.lastModified());
        System.out.println(file.getParent());
    }
    @Test
    public void test(){
        File file = new File("D:\\Lizejiang\\importantNetworkCourse\\JavaLearn\\JavaCode\\JavaSELearn\\JavaIO");
        //NullPointerException 空指针异常，文件不存在
        System.out.println(Arrays.toString(file.list()));

        File[] files = file.listFiles();
        for (File f : files) {
            System.out.println(f);
        }
    }
    @Test
    public void test1(){
        //renameTo(file)：把文件重命名为指定的文件路径（相当于剪切+重命名操作）
        File file = new File("hello.txt");
        File file1 = new File("D:\\Lizejiang\\importantNetworkCourse\\JavaLearn\\JavaCode\\JavaSELearn\\JavaIO\\hi.txt");
        boolean b = file.renameTo(file1);
        System.out.println(b);
    }

    @Test
    public void test2() {
        //file判断方法
        File file = new File("hi.txt");
        System.out.println(file.isDirectory());
        System.out.println(file.isFile());
        System.out.println(file.exists());
        System.out.println(file.canRead());
        System.out.println(file.canWrite());
        System.out.println(file.isHidden());
    }
}
